#include "s_spi.h"

//------------------------------------------------------------------------------
/// Get most up-to-date data from ADC Data Register
//------------------------------------------------------------------------------
extern inline unsigned short GetADCData()
{  
  // Read from ADC Data Register
  SPI_Read_Write(0xFF44);
  
  return SPI_Read_Write(0xFFFF);
}

//------------------------------------------------------------------------------
/// Begin new analog to digital convertion
//------------------------------------------------------------------------------
extern inline void ADCConvert(char Channel)
{ 
  // Write to Control register; #channel, unipolar, All Range
  SPI_Read_Write(0x020F | (Channel << 4)); 
  
  // Write to Mode register; no chop, 10 channels, single conversion
  SPI_Read_Write(0x01D2); // Begin next adc convertion
}
